<?php
define("UPLOADS", "../uploads/");
$catalogName = $_POST['catalogName'];

	if(isset($_FILES['uploaded_file'])) {
		$errors= array();
		$file_name = $_FILES['uploaded_file']['name'];
		$file_size =$_FILES['uploaded_file']['size'];
		$file_tmp =$_FILES['uploaded_file']['tmp_name'];
		$file_type=$_FILES['uploaded_file']['type'];  
		$file_ext=strtolower(end(explode('.',$_FILES['uploaded_file']['name'])));
		
		$extensions= array("png", "pptx", "ppt", "docx", "doc", "pdf"); 		
		
		if(in_array($file_ext, $extensions) === false) {
			$errors[]="File extension not allowed.";
		}
		
		if($file_size > 2097152) {
			$errors[]='File size must be less than 2 MB in size.';
		}		
		
		if(empty($errors) == true) {
			

			if(!is_dir(UPLOADS.$catalogName."/")) {
	    		mkdir(UPLOADS.$catalogName."/");
			} 
			
			move_uploaded_file($file_tmp, UPLOADS.$catalogName."/".$file_name);
			echo "Success!";
			
		} else {
			print_r($errors);
		}
	}
?>